package com.xian.ucenter.handler;

import cn.hutool.json.JSONUtil;
import com.xian.ucenter.commons.Result;
import com.xian.ucenter.utils.ResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AccessDeniedExceptionHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        String jsonStr = JSONUtil.toJsonStr(Result.fail("用户权限不足！"));
        // 处理异常
        ResponseUtil.out(response,jsonStr);
    }
}
